lst=[2,4,5,6,10,12,15,16,24,35] file=open("num.obj","wb") pickle.dump(lst,file) print("Success Stored...") file.close()
Success Stored…
dit={"Rollno":1001, "Name":"Amit Jain", "Branch":"CSE", "Age":16} file=open("stud.obj","wb") pickle.dump(dit,file) print("Success Stored...") file.close()
Success Stored
import pickle file=open("stud.obj","rb") dit=pickle.load(file) for key,val in dit.items(): print(key,":",val) file.close()
Rollno : 1001 Name : Amit Jain Branch : CSE Age : 16
class worker: def __init__(self,nm,wg,wd): self.name=nm self.wages=wg self.wdays=wd def showdata(self): print("Name:",self.name) print("Wages:",self.wages) print("Wdays:",self.wdays) def payment(self): p=self.wages*self.wdays print("Payment is ",p) import pickle from worker import * a=worker("Raja",500,5) b=worker("Raju",800,2) file=open("work.obj","wb") pickle.dump(a,file) pickle.dump(b,file) print("Success Stored...") file.close()
Success Stored...
class worker: def __init__(self,nm,wg,wd): self.name=nm self.wages=wg self.wdays=wd def showdata(self): print("Name:",self.name) print("Wages:",self.wages) print("Wdays:",self.wdays) def payment(self): p=self.wages*self.wdays print("Payment is ",p) import pickle from worker import * file=open("work.obj","rb") a=pickle.load(file) file=open("work.obj","rb") b=pickle.load(file) a.showdata() a.payment() b.showdata() b.payment() file.close()
Name: Raja Wages: 500 Wdays: 5 Payment is 2500 Name: Raja Wages: 500 Wdays: 5 Payment is 2500